#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    int n;
    cin >> n;
    long long prev2 = 0, prev1 = 0, current = 0;
    cin >> prev1; // prev1 is the first element when i=0

    if (n == 1) {
        cout << prev1 << endl;
        return 0;
    }

    long long num;
    cin >> num;
    prev2 = prev1;
    prev1 = max(prev2, num); // prev1 is max of first two elements when i=1

    for (int i = 2; i < n; i++) {
        cin >> num;
        current = max(prev1, prev2 + num);
        prev2 = prev1;
        prev1 = current;
    }

    cout << prev1 << endl;
    return 0;
}